package com.ee.chat.cps.admin.controller.promotemanage;

import com.ee.chat.common.bean.Result;
import com.ee.chat.common.vo.ChannelVO;
import com.ee.chat.cps.admin.service.IPromoteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author AppiJ
 * @Date 2020/4/2 15:33
 */
@RestController
@RequestMapping("promote")
public class PromoteController {
    private Logger log = LoggerFactory.getLogger(PromoteController.class);

    @Resource
    IPromoteService promoteService;

    /**
     * 获取推广地址列表
     * @Author AppiJ
     * @Date 2020/4/2 15:42
     * @return
     */
    @RequestMapping("list")
    public Result list(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit){
        try{
            return promoteService.list(request, page, limit);
        }catch (Exception e){
            log.error("【获取推广地址列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取推广渠道列表
     * @Author AppiJ
     * @Date 2020/4/10 17:01
     * @param
     * @return
     */
    @RequestMapping("channelList")
    public Result channelList(HttpServletRequest request, String keyword, @RequestParam Integer page, @RequestParam Integer limit){
        try{
            return promoteService.channelList(request, keyword, page, limit);
        }catch (Exception e){
            log.error("【获取推广渠道列表】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取渠道信息
     * @Author AppiJ
     * @Date 2020/4/13 11:57
     * @param
     * @return
     */
    @RequestMapping("toEditChannel")
    public Result toEditChannel(HttpServletRequest request, @RequestParam Integer id){
        try{
            return promoteService.toEditChannel(request, id);
        }catch (Exception e){
            log.error("【获取渠道信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 添加下级渠道
     * @Author AppiJ
     * @Date 2020/4/14 15:02
     * @param
     * @return
     */
    @RequestMapping("addChannel")
    public Result addChannel(HttpServletRequest request, ChannelVO channelVO){
        try{
            return promoteService.addChannel(request, channelVO);
        }catch (Exception e){
            log.error("【添加下级渠道错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 编辑下级渠道
     * @Author AppiJ
     * @Date 2020/4/14 18:30
     * @param
     * @return
     */
    @RequestMapping("editChannel")
    public Result editChannel(HttpServletRequest request, ChannelVO channelVO){
        try{
            return promoteService.editChannel(request, channelVO);
        }catch (Exception e){
            log.error("【编辑下级渠道错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 重置下级渠道用户密码
     * @Author AppiJ
     * @Date 2020/4/20 13:55
     * @param
     * @return
     */
    @RequestMapping("restPwd")
    public Result restPwd(HttpServletRequest request, @RequestParam Integer id){
        try {
            return promoteService.restPwd(request, id);
        } catch(Exception e){
            log.error("【重置下级渠道用户密码错误】", e);
        }
        return Result.returnFailure();
    }
}
